package com.atguigu.day31;

import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;


/**
 * @version 1.0
 * @Author 马冰
 * @Date 2024/12/10 8:42
 * @注释
 */
@WebServlet("/morning")
public class MorningServlet extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("MorningServlet 请求到达了");
        String name = req.getParameter("name");
        String pwd = req.getParameter("pwd");
        String email = req.getParameter("email");
        MorningUser user = new MorningUser(name, pwd, email);

        //req.getRequestDispatcher("login.html");

        resp.sendRedirect("login.html");

        //resp.getWriter().println("MorningServlet Success" + user);
//        MorningUser user = null;
//        ServletContext servletContext = this.getServletContext();
//        Enumeration<String> initParameterNames = servletContext.getInitParameterNames();
//        ArrayList<String> users = new ArrayList<>();
//
//
//        while (initParameterNames.hasMoreElements()) {
//            String name = initParameterNames.nextElement();
//            String value = servletContext.getInitParameter(name);
//            users.add(value);
//        }
//        user = new MorningUser(users.get(0), users.get(1), users.get(2));
//        System.out.println("user.getName() = " + user.getName());
//        System.out.println("user.getPassword() = " + user.getPassword());
//        System.out.println("user.getEmile() = " + user.getEmile());
    }
}
